<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/11/7
 * Time: 9:32
 */
namespace app\v1\model;

use think\Db;

class Businesspay extends \think\Model
{
    private $tableName = "businessPay";//表名

    /*
     * 生成商户提现
     * */
    public function addBusinesspay($data)
    {
        if (!empty($data['merchantId']) || !empty($data['amount'])) {
            $data['createTime'] = time();
            $data['payNumber'] = "";
            $data['orderStatus'] = "0";
            $data['remarks'] = "";
            $data['payTime']="";
            $data['isDelete']="0";//伪删除
            return Db::name($this->tableName)->insertGetId($data);
        } else {
            return 404;//字段填写不完整
        }

    }

    /*
     * 根据id获取订单
     * */
    public function getBusinesspayById($id)
    {
        return Db::name("userPay")->where("_id", $id)->find();
    }

    /*
     * 获取订单
     * */
    public function optionsBusinesspay($data)
    {
        $total = config("total");
        $data['page'] = empty($data['page']) ? 1 : $data['page'];
        if (empty($data['orderStatus'])) {
            return Db::name($this->tableName)->limit(($data['page'] - 1) * $total, $total)->select();
        } else {
            return Db::name($this->tableName)->where("orderStatus", $data['orderStatus'])->limit(($data['page'] - 1) * $total, $total)->select();
        }

    }

    /*
     * 根据id删除
     * */
    public function delBusinesspay($id)
    {
        return Db::name($this->tableName)->where("_id", $id)->delete();
    }

    /*
     * 更新订单
     * */
    public function putBusinesspay($data)
    {
        if ($data['orderStatus'] == 2) {

        } else {
            return Db::name($this->tableName)->update($data);
        }
    }

    /*
  * 根据支付订单原路返回金额给商户
  * @param
  *
  * */
    public function returnMoneyToUser()
    {

    }

}